﻿#include "configuredialog.h"
#include "ui_configuredialog.h"
#include <QFileDialog>
#include <QtDebug>

ConfigureDialog::ConfigureDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ConfigureDialog)
{
    ui->setupUi(this);
//    initial();
}

ConfigureDialog::~ConfigureDialog()
{
    delete ui;
}

ConfigStruct ConfigureDialog::configure() const
{
    return m_configure;
}

void ConfigureDialog::setConfigure(const ConfigStruct &configure)
{
    m_configure = configure;
}

void ConfigureDialog::initial()
{
    m_configure.enableOpenGL = true;
    m_configure.chartTheme = QChart::ChartThemeLight;
    m_configure.maxTipPoints = 10;
    m_configure.xAixsTickPoints = 5;
    m_configure.yAxisTickPoints = 5;
    m_configure.displayResolution = "800*600";

    ui->opengl_checkBox->setChecked(m_configure.enableOpenGL);
    ui->resolution_comboBox->setCurrentText(m_configure.displayResolution);
    ui->theme_comboBox->setCurrentIndex(m_configure.chartTheme);
    ui->maxTip_comboBox->setCurrentIndex(m_configure.maxTipPoints-1);
    ui->xAxisCount_comboBox->setCurrentIndex(m_configure.xAixsTickPoints-1);
    ui->yAxisCount_comboBox->setCurrentIndex(m_configure.yAxisTickPoints-1);

    emit configureFinish();

}

void ConfigureDialog::showEvent(QShowEvent *sEvent)
{

    ui->opengl_checkBox->setChecked(m_configure.enableOpenGL);
    ui->resolution_comboBox->setCurrentText(m_configure.displayResolution);
    ui->theme_comboBox->setCurrentIndex(m_configure.chartTheme);
    ui->maxTip_comboBox->setCurrentIndex(m_configure.maxTipPoints-1);
    ui->xAxisCount_comboBox->setCurrentIndex(m_configure.xAixsTickPoints-1);
    ui->yAxisCount_comboBox->setCurrentIndex(m_configure.yAxisTickPoints-1);
    ui->scrDir_label->setText(m_configure.screenShotPath);
    qDebug()<<m_configure.screenShotPath;

    __super::showEvent(sEvent);
}



void ConfigureDialog::on_ok_pushButton_clicked()
{
    m_configure.enableOpenGL = ui->opengl_checkBox->checkState();
    m_configure.chartTheme = QChart::ChartTheme(ui->theme_comboBox->currentIndex());
    m_configure.maxTipPoints = ui->maxTip_comboBox->currentIndex()+1;
    m_configure.displayResolution = ui->resolution_comboBox->currentText();
    m_configure.xAixsTickPoints = ui->xAxisCount_comboBox->currentIndex()+1;
    m_configure.yAxisTickPoints = ui->yAxisCount_comboBox->currentIndex()+1;
    m_configure.screenShotPath = ui->scrDir_label->text();
    emit configureFinish();

    this->hide();
}

void ConfigureDialog::on_cancel_pushButton_clicked()
{
    this->hide();
}



void ConfigureDialog::on_scrPath_pushButton_clicked()
{
    auto srcDirPath = QFileDialog::getExistingDirectory(
                this, tr("选择文件夹"),tr("/"));

    if(srcDirPath.isEmpty())
    {
        return;

    }else{

        srcDirPath += "/";

        ui->scrDir_label->setText(srcDirPath);


    }

}
